package com.tanhua.app.controller;

import com.tanhua.app.service.MessagesService;
import com.tanhua.model.vo.ContactVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;

    @GetMapping("/userinfo")
    public ResponseEntity userInfo(@RequestParam String huanxinId){
        UserInfoVo vo = messagesService.findUserInfoByHuanXing(huanxinId);
        return ResponseEntity.ok(vo);
    }

    //添加联系人
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        Long friendId = Long.valueOf(map.get("userId").toString());
        messagesService.contacts(friendId);
        return ResponseEntity.ok(null);
    }

    //联系人列表
    @GetMapping("/contacts")
    public ResponseEntity contactsPage(@RequestParam(defaultValue = "1") Integer page,
                                       @RequestParam(defaultValue = "10") Integer pagesize,
                                       String keyword){
         PageResult<ContactVo> pr = messagesService.contactsPage(page,pagesize,keyword);
         return ResponseEntity.ok(pr);
    }
}
